package servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "Test003Servlet", value = "/login")
public class Test003Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        if("123".equals(username) && "123".equals(password)){
            System.out.println("登录成功");

//            Cookie cookie = new Cookie("hl","0322");
//            response.addCookie(cookie);

            HttpSession session = request.getSession();
            session.setAttribute("huali","0328");

            request.getRequestDispatcher("/success.html").forward(request,response);
//            response.sendRedirect("/success.html");
            return;
        }
        System.out.println("登录失败");
        response.sendRedirect("/failing.html");

    }
}
